<template>
	<view class="sample-term-wrap">
		<view class="top_head">
			<view class="top_head_nav">
				<b style="width: 80px;">样品编号</b>
				<view class="content">{{code}}</view>
			</view>
			<view class="top_head_nav" style="margin-top: 8px;">
				<b style="width: 80px;">检测因子</b>
				<view class="content">{{factors}}</view>
			</view>
		</view>
		
		<view class="sample-term">
			<view class="center_between">
				<b style="width: 80px;">点位</b>
				<view class="content center_between">
					<view class="content" style="margin-right: 10px;text-align: left;">
						
						<input type="text" v-model="addressVal">
					</view>
					<u-icon name="edit-pen-fill" color="#193566" size="32"/>
				</view>
			</view>
		</view>	
		
		<view style="display: flex;justify-content: space-between;" >
			<view class="sample-term" style="flex: 1;margin-right: 20px;text-align: center;" @click="addFactor">
				<b style="color: #193566;">新增因子</b>
			</view>	
			<view class="sample-term" style="flex: 1;text-align: center;" @click="addFactorCombination">
				<b style="color: #193566;">新增同系因子套餐</b>
			</view>	
		</view>
		
		<view class="sample-term" style="position: relative;"  @click="detail" v-for="(item, index) in list">
			<view class="center_between">
				<b style="width: 80px;">检测因子</b>
				<view class="content center_between">
					<b class="content" style="margin-right: 10px;text-align: left;color: #193566;">
						{{item.factorName}}
					</b>
				</view>
			</view>
			<view class="center_between" style="margin: 8px 0;">
				<view style="width: 80px;font-size: 12px;">标准号</view>
				<view class="content center_between">
					<view class="content" style="margin-right: 10px;text-align: left;">
						{{item.standardNo}}
					</view>
				</view>
			</view>
			<view class="center_between" style="margin:0 0 8px 0;">
				<view style="width: 80px;font-size: 12px;">检测标准</view>
				<view class="content center_between">
					<view class="content" style="margin-right: 10px;text-align: left;">
						{{item.standardName}}
					</view>
				</view>
			</view>
			<view class="center_between">
				<view style="width: 80px;font-size: 12px;">分析方法</view>
				<view class="content center_between">
					<view class="content" style="margin-right: 10px;text-align: left;">
						{{item.analysisMethod}}
					</view>
				</view>
			</view>
			<view class="nav_btn" style="z-index: 0;">
				<u-button type="warning navSingleBtn" class="dialogBtn"  @click="del(item,index)">删除</u-button>
			</view>
		</view>	
		
		<u-empty v-if="list.length == 0"  style="margin-top:50px"></u-empty>
		
	
	</view>
</template>

<script>
	
	export default {
		props:{
			
			sampleData: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				code:'',
				factors:'',
				sampsIdArr:[],//选择改修的样品id数组
				list:[],
				addressVal:'',
				secdClassId:''
			}
		},
		onShow() {
			
		},
		mounted() {
			let codeArr = []
			let factorsArr = []
			this.sampleData.map((item)=>{
				codeArr.push(item.sampleNo)
				factorsArr.push(item.factorName)
				this.sampsIdArr.push(item.sampItemId)
			})
			this.addressVal = this.sampleData[0].factorPoint || ''
			this.secdClassId = this.sampleData[0].secdClassId || ''
			this.code = codeArr.toString()
			this.factors = factorsArr.toString()
			this.query()
			
			uni.$on('edit_querys', (query) => {
				let data = [...this.list, ...query.paramsName]
				let map = new Map();
				for (let item of data) {
					if (!map.has(item.id)) {
						map.set(item.id, item);
					};
				};
				this.list = [...map.values()]
				
				this.$emit('callbackData' ,this.list);
			});
		},
		destroyed() {
			 uni.$off('edit_querys');  
		},
		methods: {
			//批量修改样品-因子列表
			query(){
				let params = {
					sampItemIds:this.sampsIdArr.toString()
				}
				this.$api.commonForGetParam('sample/factorList',params, res => {
					if(res.code == 200) {
						this.list = res.result
					}
				})
			},
			//数组对象去重
			cnki(tempArr) {
			    let result = [];
			    let obj = {};
			    for (let i = 0; i < tempArr.length; i++) {
			        if (!obj[tempArr[i].id]) {
			            result.push(tempArr[i]);
			            obj[tempArr[i].id] = true;
			        };
			    };
			    return result;
			},
			//新增因子
			addFactor(){
				console.log('新增因子');
				let dataInfo = {
					code:this.code,
					factors:this.factors,
					addressVal:this.addressVal,
					secdClassId:this.secdClassId,
				}
				this.$common.navigateTo('/pages/sampleLeader/opt/factorOpt/addFactor?source=' + 'edit_addFactor'+ 
				'&dataInfo='  + encodeURIComponent(JSON.stringify(dataInfo)));
			},
			//新增同系因子套餐
			addFactorCombination(){
				console.log('新增同系因子套餐');
				this.$common.navigateTo('/pages/sampleLeader/opt/factorOpt/addFactorCombination');
			},
			//详情
			detail(){
				console.log('详情');
			},
			//删除
			del(item, index) {
				this.list.splice(item, 1)
				this.$emit('callbackData' ,{
					allARR:this.list,
					delID:item.checkStandardId
				});
			},
		}
	}
</script>

<style scoped>
	.center_between {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.top_head {
		background: #d7dae1;
		margin-top: 8px;
		padding: 10px;
		border-radius: 8px;
	}
	.top_head_nav {
		display: flex;
		justify-content: space-between;
		align-items: center;
		
	}
	.content {
		flex: 1;
		text-align: right;
		color: #68696d;
		overflow:hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}
	.sample-term-wrap{
		width:calc(100%-70rpx);
		display: flex;
		justify-content: center;
		flex-direction: column;
		/* align-items: center; */
		padding-left: 35rpx;
		padding-right: 35rpx;
	}
	.sample-term{
		/* width: 90%; */
		/* min-height:390rpx; */
		/* height:370rpx; */
		border-radius: 16rpx;
		background:#fff;
		padding:20rpx;
		box-shadow: 0px 3px 3px 1px rgba(0,0,0,0.16);
		margin-top: 20rpx;
	}
	.nav_btn {
		position: absolute;
		top: 16rpx;
		right: 16rpx;
	}
	.navSingleBtn {
		height: 50rpx;
		font-size: 12px;
		padding: 0 8px;
		background: #2f3a89;
		box-shadow: 1px 1px 3px #ccc;
	}
	
</style>
